/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 * \file     Icu_Types.h                                                                                *
 * \brief    This file contains the data type definitions used by the MCAL ICU driver                   *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2023/08/17     <td>1.0.0                                                                     *
 * </table>                                                                                             *
 *******************************************************************************************************/
#ifndef ICU_TYPES_H
#define ICU_TYPES_H

#ifdef __cplusplus
extern "C" {
#endif

/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/

/* autosar standard types file */
#include "Std_Types.h"

/********************************************************************************************************
 *                                      Global macro definition                                         *
 *******************************************************************************************************/
/**
 *  \addtogroup MCAL_ICU_MACRO PWM macro
 *  \{
 */
/** \{ */
/* xtrg module base address macro */
#define APBMUX_XTRG_BASE               (0xF8170000UL)
/* xtrg module total capture macro */
#define MAX_XTRG_CAPTURE_MODULE        (64U)
/* xtrg module total capture macro */
#define HALF_XTRG_CAPTURE_MODULE        (32U)
/** \} */
/** \} */
/********************************************************************************************************
 *                                      Data types definition                                           *
 *******************************************************************************************************/

/**
 *  \addtogroup MCAL_ICU_CFG ICU Configuration.
 *  \{
 */

/**********************Autosar standard data types*****************************/

/** \brief  icu channel id type (low 8 bit : channel Id for single capture mode,
high 8 bit : channel id for multi capture mode  */
/**
 * Traceability : SWSR_ICU_013
 */
typedef uint16 Icu_ChannelType;

/** \brief  Timerstamp mode buffer index (buffer size data type : uint16)  */
/**
 * Traceability : SWSR_ICU_026
 */
typedef uint16 Icu_IndexType;

/** \brief  Edge counter number  */
/**
 * Traceability : SWSR_ICU_027
 */
typedef uint32 Icu_EdgeNumberType;

/** \brief  icu common value type  */
/**
 * Traceability : SWSR_ICU_024
 */
typedef uint32 Icu_ValueType;

/**********************Semidrive customised data types*************************/

/** \brief  edge detection mode notification function  */
typedef void(*Icu_SignalNotificationType)(void);

/** \brief  timestamp mode notification function  */
typedef void(*Icu_TimestampNotificationType)(void);


/********************************************************************************************************
 *                                      Enumerated data types                                           *
 *******************************************************************************************************/

/**********************Autosar standard enum types*****************************/


/**
* \brief    Input state of an ICU channel.
*/
/**
 * Traceability : SWSR_ICU_014
 */
typedef enum
{
    /** An activation edge has been detected  */
    ICU_ACTIVE = 0U,
    /** No activation edge has been detected  */
    ICU_IDLE
} Icu_InputStateType;

/**
* \brief    definition of the type of activation of an ICU channel.
*/
/**
 * Traceability : SWSR_ICU_023
 */
typedef enum
{
    /** An appropriate action shall be executed when a rising edge occurs  */
    ICU_RISING_EDGE  = 0U,
    /** An appropriate action shall be executed when a falling edge occurs  */
    ICU_FALLING_EDGE,
    /** An appropriate action shall be executed when a signal toggles  */
    ICU_BOTH_EDGES
} Icu_ActivationType;

/**
* \brief    definition of the measurement mode type.
*/
/**
 * Traceability : SWSR_ICU_028
 */
typedef enum
{
    /** Mode for detecting edges  */
    ICU_MODE_SIGNAL_EDGE_DETECT = 0U,
    /** Mode for measuring different times between configurable edges  */
    ICU_MODE_SIGNAL_MEASUREMENT,
    /** Mode for capturing timer values on configurable edges  */
    ICU_MODE_TIMESTAMP,
    /** Mode for counting edges on configurable  */
    ICU_MODE_EDGE_COUNTER
} Icu_MeasurementModeType;

/**
* \brief    definition of the measurement property type.
*/
/**
 * Traceability : SWSR_ICU_029
 */
typedef enum
{
    /**  Reading the elapsed Signal Low Time  */
    ICU_LOW_TIME = 0U,
    /**  Reading the elapsed Signal Hign Time  */
    ICU_HIGH_TIME,
    /**  Reading the elapsed Signal Period Time  */
    ICU_PERIOD_TIME,
    /**  Calculating the duty cycle  */
    ICU_DUTY_CYCLE
} Icu_SignalMeasurementPropertyType;

/**
* \brief    Definition of the timestamp measurement property type.
*/
/**
 * Traceability : SWSR_ICU_030
 */
typedef enum
{
    /**  Buffer will just be filled once  */
    ICU_LINEAR_BUFFER = 0U,
    /**  The driver can restarts at the beginning of the buffer  */
    ICU_CIRCULAR_BUFFER
} Icu_TimestampBufferType;


/**********************Semidrive customised enum types*************************/

/**
* \brief    hardware modules used in icu driver.
*/
typedef enum
{
    /**  The etimer1 modue  */
    ICU_INDEX_ETIMER1 = 0U,
    /**  The etimer2 modue  */
    ICU_INDEX_ETIMER2,
    /**  The etimer3 modue  */
    ICU_INDEX_ETIMER3,
    /**  The etimer4 modue  */
    ICU_INDEX_ETIMER4
} Icu_HwModule;

/**
* \brief    hardware channel used in icu driver.
*/
typedef enum
{
    /**  The etimer capture a channel  */
    ICU_HW_CPT_A  = 0U,
    /**  The etimer capture b channel  */
    ICU_HW_CPT_B,
    /**  The etimer capture c channel  */
    ICU_HW_CPT_C,
    /**  The etimer capture d channel  */
    ICU_HW_CPT_D
} Icu_HwChannel;

/**
* \brief    hardware channel used in icu xtrg driver.
*/
typedef enum
{
    /**  The xtrg channel 00 */
    ICU_XTRG_CHAN_00  = 0U,
    /**  The xtrg channel 01  */
    ICU_XTRG_CHAN_01,
    /**  The xtrg channel 02  */
    ICU_XTRG_CHAN_02,
    /**  The xtrg channel 03  */
    ICU_XTRG_CHAN_03,
    /**  The xtrg channel 04  */
    ICU_XTRG_CHAN_04,
    /**  The xtrg channel 05  */
    ICU_XTRG_CHAN_05,
    /**  The xtrg channel 06  */
    ICU_XTRG_CHAN_06,
    /**  The xtrg channel 07  */
    ICU_XTRG_CHAN_07,
    /**  The xtrg channel 08  */
    ICU_XTRG_CHAN_08,
    /**  The xtrg channel 09  */
    ICU_XTRG_CHAN_09,
    /**  The xtrg channel 10  */
    ICU_XTRG_CHAN_10,
    /**  The xtrg channel 11  */
    ICU_XTRG_CHAN_11,
    /**  The xtrg channel 12  */
    ICU_XTRG_CHAN_12,
    /**  The xtrg channel 13  */
    ICU_XTRG_CHAN_13,
    /**  The xtrg channel 14  */
    ICU_XTRG_CHAN_14,
    /**  The xtrg channel 15  */
    ICU_XTRG_CHAN_15,
    /**  The xtrg channel 16  */
    ICU_XTRG_CHAN_16,
    /**  The xtrg channel 17  */
    ICU_XTRG_CHAN_17,
    /**  The xtrg channel 18  */
    ICU_XTRG_CHAN_18,
    /**  The xtrg channel 19  */
    ICU_XTRG_CHAN_19,
    /**  The xtrg channel 20  */
    ICU_XTRG_CHAN_20,
    /**  The xtrg channel 21  */
    ICU_XTRG_CHAN_21,
    /**  The xtrg channel 22  */
    ICU_XTRG_CHAN_22,
    /**  The xtrg channel 23  */
    ICU_XTRG_CHAN_23,
    /**  The xtrg channel 24  */
    ICU_XTRG_CHAN_24,
    /**  The xtrg channel 26  */
    ICU_XTRG_CHAN_25,
    /**  The xtrg channel 26  */
    ICU_XTRG_CHAN_26,
    /**  The xtrg channel 27  */
    ICU_XTRG_CHAN_27,
    /**  The xtrg channel 28  */
    ICU_XTRG_CHAN_28,
    /**  The xtrg channel 29  */
    ICU_XTRG_CHAN_29,
    /**  The xtrg channel 30  */
    ICU_XTRG_CHAN_30,
    /**  The xtrg channel 31  */
    ICU_XTRG_CHAN_31,
    /**  The xtrg channel 32 */
    ICU_XTRG_CHAN_32,
    /**  The xtrg channel 33  */
    ICU_XTRG_CHAN_33,
    /**  The xtrg channel 34  */
    ICU_XTRG_CHAN_34,
    /**  The xtrg channel 35  */
    ICU_XTRG_CHAN_35,
    /**  The xtrg channel 36  */
    ICU_XTRG_CHAN_36,
    /**  The xtrg channel 37  */
    ICU_XTRG_CHAN_37,
    /**  The xtrg channel 38  */
    ICU_XTRG_CHAN_38,
    /**  The xtrg channel 39  */
    ICU_XTRG_CHAN_39,
    /**  The xtrg channel 40  */
    ICU_XTRG_CHAN_40,
    /**  The xtrg channel 41  */
    ICU_XTRG_CHAN_41,
    /**  The xtrg channel 42  */
    ICU_XTRG_CHAN_42,
    /**  The xtrg channel 43  */
    ICU_XTRG_CHAN_43,
    /**  The xtrg channel 44  */
    ICU_XTRG_CHAN_44,
    /**  The xtrg channel 45  */
    ICU_XTRG_CHAN_45,
    /**  The xtrg channel 46  */
    ICU_XTRG_CHAN_46,
    /**  The xtrg channel 47  */
    ICU_XTRG_CHAN_47,
    /**  The xtrg channel 48  */
    ICU_XTRG_CHAN_48,
    /**  The xtrg channel 49  */
    ICU_XTRG_CHAN_49,
    /**  The xtrg channel 50  */
    ICU_XTRG_CHAN_50,
    /**  The xtrg channel 51  */
    ICU_XTRG_CHAN_51,
    /**  The xtrg channel 52  */
    ICU_XTRG_CHAN_52,
    /**  The xtrg channel 53  */
    ICU_XTRG_CHAN_53,
    /**  The xtrg channel 54  */
    ICU_XTRG_CHAN_54,
    /**  The xtrg channel 55  */
    ICU_XTRG_CHAN_55,
    /**  The xtrg channel 56  */
    ICU_XTRG_CHAN_56,
    /**  The xtrg channel 57  */
    ICU_XTRG_CHAN_57,
    /**  The xtrg channel 58  */
    ICU_XTRG_CHAN_58,
    /**  The xtrg channel 59  */
    ICU_XTRG_CHAN_59,
    /**  The xtrg channel 60  */
    ICU_XTRG_CHAN_60,
    /**  The xtrg channel 61  */
    ICU_XTRG_CHAN_61,
    /**  The xtrg channel 62  */
    ICU_XTRG_CHAN_62,
    /**  The xtrg channel 63  */
    ICU_XTRG_CHAN_63
} Icu_XtrgHwChannel;


/**
* \brief    hardware channel used in icu xtrg driver.
*/
typedef enum
{
    /**  The xtrg1 module  */
    ICU_INDEX_XTRG1 = 0U,
    /**  The xtrg2 module  */
    ICU_INDEX_XTRG2,
} Icu_XtrgHwModule;

/**
* \brief    clock source used by hardware module.
*/
typedef enum
{
    /**  High frequency clock  */
    ICU_SEL_HF_CLK = 0U,
    /**  Alternative high frequency clock  */
    ICU_SEL_AHF_CLK,
    /**  External clock  */
    ICU_SEL_EXT_CLK,
    /**  Low power clock  */
    ICU_SEL_LP_CLK
} Icu_ClockRefType;

/**
* \brief    edge change types in multi capture mode.
*/
typedef enum
{
    /**  A rising edge occurs in multi capture mode */
    ICU_MULTI_CPT_RISING_EDGE = 0U,
    /**  A falling edge occurs in multi capture mode */
    ICU_MULTI_CPT_FALLING_EDGE
} Icu_MultiCptEdgeChangeType;

/**
* \brief    icu driver initial status.
*/
typedef enum
{
    /** The driver has been initilized */
    ICU_STATUS_UNINIT = 0U,
    /** The driver not initilized yet */
    ICU_STATUS_INITED
} Icu_InitialStateType;

/********************************************************************************************************
 *                                          Struct data types                                           *
 *******************************************************************************************************/

/*********************Semidrive customised struct types************************/

/**
* \brief    parameter settings for icu measurement mode.
*/
typedef struct
{
    struct
    {
        /**  notification function point to edge detection mode */
        Icu_SignalNotificationType sigNotifyFuncPtr;
        /**  whether to call function in edge detection mode */
        boolean notifyEdgeDetDefault;
    } Icu_SignalEdgeDetection;
    /**  sub-mode in signal measurement mode */
    Icu_SignalMeasurementPropertyType sigMeasureProperty;
    struct
    {
        /**  buffer-mode in timestamp mode */
        Icu_TimestampBufferType tsBufferProperty;
        /**  whether to call function in timestamp mode */
        boolean notifyTsDefault;
        /**  notification function point to timestamp mode */
        Icu_TimestampNotificationType tsNotifyFuncPtr;
    } Icu_TimestampMeasurement;
} Icu_MeasureModeParamType;

/**
* \brief    hardware channel information
*/
typedef struct
{
    /**  etimer module select */
    Icu_HwModule timerModule;
    /**  etimer channel select */
    Icu_HwChannel timerChannel;
    /**  etimer frequency division value */
    uint16 timerPrescaler;
    /**  etimer clock source select */
    Icu_ClockRefType timerClock;
    /**  multi capture channel number */
    uint8 multiCptChanNum;
} Icu_HwChannelConfigType;

/**
* \brief    mode select and parameter settings for multi capture channel
*/
typedef struct
{
    struct
    {
        /**  default activation for edge count mode */
        Icu_ActivationType edgeCntMulStartEdge;
    } Icu_MultiCptEdgeCount;
    struct
    {
        /**  buffer mode for timestamp mode */
        Icu_TimestampBufferType tsBufferMulProperty;
        /**  default activation for timestamp mode */
        Icu_ActivationType tsMulStartEdge;
        /**  whether to call function in timestamp mode */
        boolean notifyTsMulDefault;
        /**  notification function point to timestamp mode */
        Icu_TimestampNotificationType notifyTsMulFuncPtr;
    } Icu_MultiCptTimestamp;
    struct
    {
        /**  sub-mode in signal measurement mode */
        Icu_SignalMeasurementPropertyType sigMeasureMulProperty;
        /**  default activation for signal measurement mode */
        Icu_ActivationType sigMeasureMulStartEdge;
    } Icu_MultiCptSigMeasure;
    /**  measurement mode select */
    Icu_MeasurementModeType icuMeasurementModeMul;
} Icu_MultiCptChanType;

/**
* \brief    mode select and parameter settings for redundancy check channel
*/
typedef struct
{
    /**  redundancy check channel index */
    Icu_IndexType icuRedundancyCheckChannel;
    /**  etimer module select for redundancy check */
    Icu_HwModule timerModule;
    /**  etimer channel select for redundancy check */
    Icu_HwChannel timerChannel;
} Icu_redundancyCheckChanType;

/**
* \brief    icu channel configuration
*/
typedef struct
{
    /**  icu channel index */
    Icu_IndexType icuChannel;
    /**  support multi capture mode or not */
    boolean multiCaptureEnable;
    /**  default activation for the channel */
    Icu_ActivationType icuDefaultStartEdge;
    /**  measurement mode select */
    Icu_MeasurementModeType icuMeasurementMode;
    /**  hardware filter level */
    uint16 icuFilterLevel;
    /**  support redundancy check or not */
    boolean redundancyCheckEnable;
    /**  point to the parameter configuration to the measurement mode */
    const Icu_MeasureModeParamType* measureParamPtr;
    /**  point to the hardware channel config */
    const Icu_HwChannelConfigType* icuHwChanCfgPtr;
    /**  point to the multi capture channel config */
    const Icu_MultiCptChanType* multiCptChanCfgPtr;
    /**  point to the redundancy check channel config */
    const Icu_redundancyCheckChanType* redundancyCheckChanCfgPtr;
    /**  core id */
    uint8 icuCoreId;
} Icu_ChannelConfigType;

/**
* \brief    icu xtrg channel configuration
*/
typedef struct
{
    /**  icu xtrg channel index */
    Icu_IndexType icuXtrgChannel;
    /**  icu xtrg hardware module */
    Icu_XtrgHwModule icuXtrgHwModule;
    /**  icu xtrg hardware channel */
    Icu_XtrgHwChannel icuXtrgHwChan;
    /**  default activation for the channel */
    Icu_ActivationType icuXtrgDefStartEdge;
    /**  measurement mode select */
    Icu_MeasurementModeType icuXtrgMeasureMode;
    /**  icu xtrg pin id */
    uint32 icuXtrgPinId;
    /**  point to the parameter configuration to the measurement mode */
    const Icu_MeasureModeParamType* xtrgMeasureParamPtr;
} Icu_XtrgChannelConfigType;

/***************** *****Autosar standard struct types**** *********************/

/**
* \brief    icu initialization channel configuration
*/
/**
 * Traceability : SWSR_ICU_015
 */
typedef struct
{
    /**  point to the icu channnels configuration */
    const Icu_ChannelConfigType (*chanConfigPtr)[];
    /**  point to the icu xtrg channnels configuration */
    const Icu_XtrgChannelConfigType (*xtrgChanConfigPtr)[];
} Icu_ConfigType;

/**
* \brief    icu dutycycle and period information
*/
/**
 * Traceability : SWSR_ICU_025
 */
typedef struct
{
    /**  dutycyle time */
    Icu_ValueType ActiveTime;
    /**  period time */
    Icu_ValueType PeriodTime;
} Icu_DutyCycleType;

/** \} */
/* end of MCAL_ICU_CFG ICU Configuration. */

#ifdef __cplusplus
}
#endif

#endif /* ICU_TYPES_H */
/* End of file */
